
# 左右节点判断，确保左右节点在非val的位置上，若left=val,与right非val值交换，直到right < left为止
def l27(nums,val):
    left = 0
    right = len(nums) - 1
    while left <= right: #长度为1的情况
        while nums[right] == val:
            right -= 1
            if right < left:break #有break语句时，不执行else;while正常退出时执行else
        else:
            if nums[left] == val:
                nums[left] = nums[right]
                right -= 1
            left += 1

    print(left,nums[0:left])
    res = [left,nums[0:left]]
    return res

    pass

# 快慢指针
def l27_(nums,val):
    slow = fast = 0
    for i in range(len(nums)):
        if val == nums[fast]:
            fast += 1
        else:
            nums[slow] = nums[i]
            fast += 1
            slow += 1
    return [slow,nums[0:slow]]




if __name__ == '__main__':

    #print( l_70(5))
    #print(ll(45))
    # l27([3,2,2,3],3)
    # l27([0,1,2,2,3,0,4,2],2)
    # l27([2],3)
    #
    # l27([2,2,2,2],2)
    pass